package auth

import (
	"context"
	"time"
)

type ValidatorOptions struct {
	NeedGenerate bool // 是否需要生成用于提交验证密码字符串， 默认为 false ,  为true是表示 输入的password是实际密码
	Ctx          context.Context
}

type ValidatorOption func(*ValidatorOptions)

func NewValidatorOptions(opts ...ValidatorOption) *ValidatorOptions {
	options := &ValidatorOptions{
		NeedGenerate: false,
		Ctx:          context.TODO(),
	}

	for _, o := range opts {
		o(options)
	}

	return options
}

func WithValidNeedGenerate(need bool) ValidatorOption {
	return func(o *ValidatorOptions) {
		o.NeedGenerate = need
	}
}

////////////////////////////////////////////////////////////////

type StoreOptions struct {
	NeedGenerate bool // 是否需要生成存储的密码， 默认为 false ,  为true是表示 输入的password是实际密码，需要生成存储密码
	Ctx          context.Context
}
type StoreOption func(*StoreOptions)

func NewStoreOptions(opts ...StoreOption) *StoreOptions {
	options := &StoreOptions{
		NeedGenerate: false,
		Ctx:          context.TODO(),
	}

	for _, o := range opts {
		o(options)
	}

	return options
}

func WithStoreNeedGenerate(need bool) StoreOption {
	return func(o *StoreOptions) {
		o.NeedGenerate = need
	}
}

////////////////////////////////////////////////////////////////

type TokenOptions struct {
	Duration  time.Duration
	SecretKey string
	Ctx       context.Context
}
type TokenOption func(*TokenOptions)

func NewTokenOptions(opts ...TokenOption) *TokenOptions {
	options := &TokenOptions{
		//NeedGenerate: false,
		Ctx: context.TODO(),
	}

	for _, o := range opts {
		o(options)
	}

	return options
}

func WithDuration(d time.Duration) TokenOption {
	return func(o *TokenOptions) {
		o.Duration = d
	}
}

func WithSecretKey(key string) TokenOption {
	return func(o *TokenOptions) {
		o.SecretKey = key
	}
}
